-- --------------------------------------------------------- --
-- this lua file saves configurations of LSP server for nvim --
-- --------------------------------------------------------- --
return {
    {
        -- mason: portable package manager for nvim lunguage support
        "williamboman/mason.nvim",
        config = function()
            require("mason").setup()
        end,
    },
    {
        -- bridges between `mason` and `nvim-lspconfig`, aim to make better experience using `mason`
        "williamboman/mason-lspconfig.nvim",
        opts = {},
        dependencies = {
            { "williamboman/mason.nvim", opts = {} },
            "neovim/nvim-lspconfig",
        },
        config = function()
            require("mason-lspconfig").setup({
                ensure_installed = { "lua_ls", "clangd" },
                handler = nil,
            })
        end,
    },
    {
        -- an asynchronous linter plugin
        "mfussenegger/nvim-lint",
        config = function ()
            -- define basic file type map
            require("lint").linters_by_ft = {
                sh = {"shellcheck"}, -- shell scripts linter support
            }
        end
    },
    {
        -- automatic pair linter server to nvim-lint
        "rshkarin/mason-nvim-lint",
        dependencies = {
            "williamboman/mason.nvim",
            "mfussenegger/nvim-lint",
        },
        config = function ()
            require("mason-nvim-lint").setup()
        end
    },
    {
        "neovim/nvim-lspconfig",
        config = function()
            local lspconfig = require("lspconfig")
            -- start your LSP here
            local capabilities = require("cmp_nvim_lsp").default_capabilities()

            lspconfig.lua_ls.setup({
                capabilities = capabilities,
                Lua = {
                    completion = {
                        calllSnippet = "Replace",
                    },
                },
            })
            lspconfig.clangd.setup({
                capabilities = capabilities,
                settings = {
                    clangd = {
                        format = {
                            style = "file",
                            fallbackStyle = "LLVM",
                        },
                    },
                },
            })
            lspconfig.bashls.setup({
                capabilities = capabilities,
            })
            lspconfig.biome.setup({
                cmd = { "biome", "lsp-proxy" },
                filetypes = { "javascript", "typescript", "json" },
                root_dir = lspconfig.util.root_pattern("biome.json"), -- 需项目根目录存在 biome.json
                capabilities = capabilities,
            })
            lspconfig.asm_lsp.setup({
                capabilities = capabilities,
            })
            lspconfig.dockerls.setup({
                capabilities = capabilities,
            })
            lspconfig.sqlls.setup({
                capabilities = capabilities,
            })
            lspconfig.yamlls.setup({
                capabilities = capabilities,
                settings = {
                    yaml = {
                        schemas = {
                            ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] =
                            "**/docker-compose*.yml",
                        },
                    },
                },
            })
            lspconfig.cmake.setup({
                capabilities = capabilities,
            })
        end,
    },
}
